<template>
  <div>
    <h1>方案管理</h1>
    <div>
      <el-button type="primary" @click="contentadd">商品方案添加</el-button>
    </div>
    <div>
    <el-form :inline="true" :model="tbCasees" class="demo-form-inline">
      <el-form-item label="名称">
        <el-input v-model="tbCasees.caseName" placeholder="审批人"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
  </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column
        prop="caseId"
        label="方案ID"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="caseName"
        label="方案名称"
        width="180"
      >
        <template slot-scope="obj">
          <span v-html="obj.row.caseName"></span>
        </template>
      </el-table-column>
      <el-table-column
        prop="askDiseaser"
        label="疾病ID"
        width="180"
      ></el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleClick(scope.row)">
            删除
          </el-button>
          <el-button type="text" size="small" @click="casecontent(scope.row)">查看改善方案</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-pagination
        :current-page="current"
        :page-sizes="[1, 2, 3, 5]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totel"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
    <div>
      <el-dialog title="添加方案" :visible.sync="dialogFormVisible">
        <el-form :model="caseContentVo">
          <el-form-item label="方案名称" :label-width="formLabelWidth">
            <el-input
              v-model="caseContentVo.caseName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-button type="primary" @click="recordsadd">添加</el-button>
          <el-table
            :data="caseContentVo.tbCaseContents"
            style="width: 100%">
            <el-table-column
              label="内容"
              width="180">
              <template slot-scope="obj">
                <el-input v-model="obj.row.content" autocomplete="off"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              label="类型"
              width="180">
              <template slot-scope="obj">
                <el-input v-model="obj.row.typeid" autocomplete="off"></el-input>
                <el-select v-model="obj.row.typeid" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.id"
                    :label="item.typename"
                    :value="item.id">
                  </el-option>
                </el-select>
              </template>
            </el-table-column>

          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addcase()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div>
      <el-dialog title="收货地址" :visible.sync="dialogFormVisible2">
        <el-table :data="tableData2" style="width: 100%">
          <el-table-column prop="id" label="ID" width="180"></el-table-column>
          <el-table-column
            prop="content"
            label="介绍"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="typeid"
            label="类型"
            width="180"
          >
            <template slot-scope="obj">
              {{aa[obj.row.typeid]}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="taskadds(scope.row)">
                领取任务
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible2 = false">取 消</el-button>
          <el-button type="primary" @click="addcase()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import { taskAdd,caselist,casePage,caseDelete,casecontentadd,caseadd,caseEsPage,caseContentBycaseid,caseType} from "@/api/case.js";
  export default {
    name: 'Caselist',
    data() {
      return {
        aa:{
          1:"运动",
          2:"食谱",
          3:"设备",
          4:"学习",
        },
        options: [],
        tableData: [],
        tableData2: [],
        dialogFormVisible: false,
        dialogFormVisible2: false,
        formLabelWidth: '120px',
        tbCase: {
          delete: '',
          current: 1,
          pagesize: 5,
        },
        totel: 0,
        tbCasea: {},
        tbCaseadd: {
          caseName: '',
        },
        tbCasees:{
          current: 1,
          pagesize: 5,
          total: 0,
          askDiseaser: '',
          caseName: '',
        },
        tbCaseContentid:{
          caseid: '',
        },
        tbTaskadd:{

        },
        caseContentVo:{
          caseName: '',
          deleted: 1,
          tbCaseContents:[{
            content: '',
            deleted: 1,
          }]
        }
      }
    },
    mounted() {
      // this.casepage()
      this.caseEsPage()
      this.casetypelist()
    },
    methods: {
      casetypelist() {
        caseType().then((res) => {
          console.log(res)
          this.options = res.data
        })
      },
      list() {
        caselist().then((res) => {
          this.tableData = res.data
        })
      },
      casepage() {
        casePage(this.tbCase).then((res) => {
          this.tableData = res.data.records;
          this.totel = res.data.total;
          console.log(res)
        })
      },
      caseEsPage(){
        caseEsPage(this.tbCasees).then((res)=>{
          console.log(res)
          this.tableData = res.data.list;
          this.totel = res.data.total;
        })
      },
      handleSizeChange(val) {
        this.tbCasees.pagesize = val
        this.caseEsPage()
        console.log(`每页 ${val} 条`)
      },
      handleCurrentChange(val) {
        this.tbCasees.current = val
        this.caseEsPage()
        console.log(`当前页: ${val}`)
      },
      // contentadd() {
      //   this.dialogFormVisible=true
      //   //this.$router.push('recipe')
      // },
      handleClick(row) {
        this.tbCasea.caseId = row.caseId
        caseDelete(this.tbCasea).then((res) => {
          this.caseEsPage()
          console.log(res)
        })
      },
      contentadd() {
        this.dialogFormVisible = true
      },
      addcase() {
        alert(this.caseContentVo)
        caseadd(this.caseContentVo).then((res) => {
          this.caseEsPage()
          console.log(res)
          this.dialogFormVisible = false
        })
      },
      onSubmit(){
        this.caseEsPage()
      },
      casecontent(row){
        this.dialogFormVisible2=true;
        this.tbCaseContentid.caseid=row.caseId;
        caseContentBycaseid(this.tbCaseContentid).then((res)=>{
          this.tableData2=res.data;
        })
      },
      taskadds(row){
        this.tbTaskadd.taskName=row.content;
        this.tbTaskadd.taskType=row.typeid;
        // this.tbTaskadd.taskUid=
        this.tbTaskadd.taskCaseid=row.caseId;
        alert(this.tbTaskadd.taskType)
        taskAdd(this.tbTaskadd).then((res)=>{
          console.log(res)
        })
      },
      recordsadd(){
        this.caseContentVo.tbCaseContents.push({});
      },

    },
  }
</script>

<style scoped></style>
